package com.itheima.mRadix.demo;

public class Demo5 {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        //method1(a, b);

        //需求: 不容许使用第三个变量, 交换a和b的值
        //一个数被另一个数异或两次,得到的还是原数本身
        System.out.println(a ^ b ^ b);

        a = a ^ b;      // a = 10 ^ 20;
        b = a ^ b;      // b = 10 ^ 20 ^ 20  --> b = 10
        a = a ^ b;      // a = 10 ^ 20 ^ 10  --> a = 20
        System.out.println("a = " + a);
        System.out.println("b = " + b);


    }

    private static void method1(int a, int b) {
        //需求: 交换变量a和b的值
        int temp = a;
        a = b;
        b = temp;

        System.out.println("a = " + a);
        System.out.println("b = " + b);
    }
}
